<template>
  <div>
    <el-table :cell-style="{ padding: this.tablePadding }" :data="list" height="200">
      <el-table-column
        label="材料名称"
        align="center"
        prop="materialName"
      />
      <el-table-column
        label="计量单位"
        align="center"
        prop="unitName"
      />
      <el-table-column
        label="消耗量"
        align="center"
        prop="amount"
      />
      <el-table-column label="单价" align="center" prop="materialPrice" />
      <el-table-column label="金额" align="center" prop="money" />
      <el-table-column
        label="送粉方向"
        align="center"
        prop="supplyMethod"
        :formatter="methodFormat"
      />
      <el-table-column label="备注" align="center" prop="remark" />
    </el-table>
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { getTechnologyWorkingMaterial } from "@/api/technology/working";
export default {
  props:{
    id:{
      type: [String,Number],
      default: null,
    },
  },
  data() {
    return {
      total: 0,
      list: [],
      queryParams: {
        workingId: "",
        pageNum: 1,
        pageSize: 10,
      },
      supplyMethodOptions:[]
    };
  },
  created(){
    this.getDicts("supply_method").then((response) => {
      this.supplyMethodOptions = response.data;
    });
  },
  watch: {
    id(newId) {
       this.list = [];
        this.total = 0;
        this.queryParams = {
          workingId: "",
          pageNum: 1,
          pageSize: 10,
        };
      if (newId == "") {
        return;
      }
      this.queryParams.workingId = newId;
      this.getList();
    },
  },
  methods: {
    // 不传入porp,则通过这个方法获取
    getInfo(id){
      this.queryParams.workingId=id
      this.getList();
    },
    methodFormat(row){
       let status = this.selectDictLabel(this.supplyMethodOptions, row.supplyMethod);
      return status;
    },
    getList() {
      getTechnologyWorkingMaterial(this.queryParams).then((response) => {
        this.list = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
  },
};
</script>

<style>
</style>